<?php

class Application_Model_User extends Mylab_Model
{
  public function __construct($id = null)
  {
    parent::__construct(new Application_Model_DbTable_Users(), $id);
  }

  public function authorize($email, $password)
  {
    $auth = Zend_Auth::getInstance();
    $authAdapter = new Zend_Auth_Adapter_DbTable(
      $this->_dbTable->getDefaultAdapter(),
      'users',
      'email',
      'password',
      'md5(?)'
    );
    $authAdapter->setIdentity($email)
      ->setCredential($password);

    $result = $auth->authenticate($authAdapter);
    if ($result->isValid()) {
      $storege = $auth->getStorage();
      $storege->write($authAdapter->getResultRowObject(null, array('password')));
      return true;
    } else {
      return false;
    }
  }
}

